﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Vacabulary
{
    public partial class Form1 : Form
    {
        string currentEnglish;
        public Form1()
        {
            InitializeComponent();
            DBHelper.InitializeDatabase();
            LoadNewWord();
            txtInput.KeyDown += TxtInput_KeyDown;
        }

        private void LoadNewWord()
        {
            var word = DBHelper.GetRandomWord();
            if (word.Chinese == null) return;

            lblChinese.Text = word.Chinese;
            currentEnglish = word.English.ToLower().Trim();
            txtInput.Clear();
            txtInput.Focus();
            lblResult.Text = "";
        }

        private void TxtInput_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                CheckAnswer();
            }
        }

        private void CheckAnswer()
        {
            string userInput = txtInput.Text.Trim().ToLower();
            lblResult.Text = userInput == currentEnglish ?
                "✓ 正确！" : $"✗ 错误！正确答案：{currentEnglish}";
            lblResult.ForeColor = userInput == currentEnglish ? Color.Green : Color.Red;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            LoadNewWord();
        }
    }
}
